<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1">
    <meta name="referrer" content="never">
    <title>不定参函数</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        ul {
            list-style: none;
        }
    </style>
</head>
<body>
    
    <script type="text/javascript">
        /* 
        参数个数不固定的函数，称为不定参函数
            关键：arguments
        
        ES6简化： 剩余参数  function([a,b,c], ...变量名){} 除去已知形参对应的实参外，多余的实参的集合，是一个数组
            剩余参数必须写在所有形参的最后
        */

        function sum(...arr){
            console.log("剩余参数", arr, Array.isArray(arr));
            var count = 0;
            // for(var i = 0; i < arr.length; i ++){
            //     count += arr[i];
            // }
            arr.forEach(function (item){
                count += item;
            })
            console.log(count);
        }

        sum(1,2,3,5,6,7,8);
    </script>
</body>
</html>